<%-- 
    Document   : TimKiem
    Created on : Oct 20, 2012, 7:53:56 AM
    Author     : DAT
--%>

<%@page import="pojo.LoaiSanPham"%>
<%@page import="dao.LoaiSanPhamDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="pojo.SanPham"%>
<%@page import="java.util.List"%>
<%@page import="dao.SanPhamDAO"%>
<%@page import="dao.ThuongHieuDAO"%>
<%@page import="pojo.ThuongHieu"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/Shoes.dwt" codeOutsideHTMLIsLocked="false" -->
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>
    </head>

    <body background="images/Blue_Background.png">
        <%
            String maThuongHieu = "-1";
            String giaBan = "150000";
            if(request.getParameter("giaBan")!=null){
                giaBan=request.getParameter("giaBan");
            }
            ThuongHieu ThuongHieu = ThuongHieuDAO.layThongTinThuongHieu(Integer.parseInt(maThuongHieu));
            int soLuongSanPhamTrenTrang = 2;
            if (request.getParameter("soLuongSanPhamTrenTrang") != null) {
                soLuongSanPhamTrenTrang = Integer.parseInt(request.getParameter("soLuongSanPhamTrenTrang"));
            }
            int trang = 1;
            if (request.getParameter("trang") != null) {
                trang = Integer.parseInt(request.getParameter("trang"));
            }
            
        %>
        <table width="1034" height="455" align="center" border="1" bordercolor="#FFFFFF">
            <tr align="center">
                <td colspan="5" valign="middle"><img src="images/BannerShoes.gif" width="1024" height="247"/></td>
            </tr>
            <tr>
                <td width="200" align="center"><a href="TrangChu.jsp"><img src="images/Button-Trangchu.gif" width="179" height="48"/></a></td>
                <td width="200" align="center"><a href="TrangDangKy"><img src="images/Button-Nam.gif" width="179" height="48"/></a></td>
                <td width="200" align="center"><a href="TrangChu"><img src="images/Button-Nu.gif" width="179" height="48"/></a></td>
                <td width="200" align="center"><a href="TrangChu"><img src="images/Button-Treem.gif" width="179" height="48"/></a></td>
                <td width="200" align="center"><a href="TrangChu"><img src="images/Button-Gioithieu.gif" width="179" height="48"/></a></td>
            </tr>
            <tr align="center">
                <%
                    List<ThuongHieu> list = ThuongHieuDAO.layDanhSach();
                    List<LoaiSanPham> dsLoaiSP = LoaiSanPhamDAO.layDanhSachLoaiSanPham();
                    List<SanPham> dsSP = SanPhamDAO.layDanhSachSanPham();
                %>

                <!-- bat dau phan tim kiem-->
                <form action="TimKiem.jsp">
                    <td colspan="5">
                        <p align="right"><font color="#0066FF"><strong>Tìm kiếm theo:</strong></font>

                            <select name="thuongHieu" size="1" style="width:15%">
                                <option value="-1" selected="selected">--Chọn thương hiệu--</option>
                                <%
                                    for (int i = 0; i < list.size(); i++) {
                                        ThuongHieu thuongHieu = list.get(i);
                                %>
                                <option value="<%=thuongHieu.getMaThuongHieu()%>"><%=thuongHieu.getTenThuongHieu()%></option>
                                <%}
                                    if (request.getParameter("thuongHieu") != null) {
                                        maThuongHieu = request.getParameter("thuongHieu");
                                    }
                                %>
                            </select>

                            <select name="loaiSanPham" style="width:15%">
                                <option value="Tất cả" selected="selected">--Chọn loại--</option>
                                <%
                                    for (int i = 0; i < dsLoaiSP.size(); i++) {
                                        LoaiSanPham loaiSanPham = dsLoaiSP.get(i);
                                %>
                                <option value="<%= loaiSanPham.getMaLoaiSanPham()%>"><%=loaiSanPham.getTenLoaiSanPham()%></option>
                                <% }
                                    String maLoai = "L001";
                                    if (request.getParameter("loaiSanPham") != null) {
                                        maLoai = request.getParameter("loaiSanPham");
                                    }
                                %>
                            </select>

                            <select name="kichCo" style="width:15%">
                                <option value="-1" selected="selected">--Chọn kích cỡ--</option>
                                <%
                                    for (int i = 0; i < dsSP.size(); i++) {
                                        SanPham sp = dsSP.get(i);
                                %>
                                <option value=<%= sp.getSize()%> ><%= sp.getSize()%></option>
                                <% }
                                    String size = "1";
                                    if (request.getParameter("kichCo") != null) {
                                        size = request.getParameter("kichCo");
                                    }
                                %>
                            </select>

                            <select name="giaBan" style="width:15%">
                                <option value="140000" selected="selected">--Chọn giá--</option>
                                <option value="150000">&lt; 150,000</option>
                                <option value="250000">150,000 - 250,000</option>
                                <option value="500000">250,000 -500,000</option>
                                <option value=">500,000">&gt; 500,000</option>
                            </select>

                            <input type="submit" value="Tìm kiếm" name="timKiem" >

                            </input>           
                        </p>
                        <!--ket thuc tim kiem-->
                    </td>
                </form>
            </tr>
            <tr>
                <td height="294" align="center">
                    <table width="100%" height="190" cellpadding="5" cellspacing="0" background="images/background.jpg">
                        <tr>
                            <td height="30" align="center" background="images/Bartop.gif"><p><strong><font color="#FFFFFF">THƯƠNG HIỆU</font></strong></p></td>
                        </tr>                      
                        <!--BatDauThuongHieu-->
                        <%
                            for (int i = 0; i < list.size(); i++) {
                                ThuongHieu dm = list.get(i);
                        %>
                        <tr>
                            <td>               
                                <a href="DanhSachSanPham.jsp?maThuongHieu=<%=dm.getMaThuongHieu()%>"><%=dm.getTenThuongHieu()%></a>
                            </td>
                        </tr>  
                        <%}%>
                    </table>
                    <table width="100%" background="images/background.jpg" >
                        <tr>
                            <td colspan="2" height="30" align="center" background="images/Bartop.gif"><p><strong><font color="#FFFFFF">LOẠI SẢN PHẨM</font></strong></p></td>
                        </tr>
                        <tr>
                            <td width="51"><img src="images/kids_dep.gif"/></td>
                            <td width="137"><a><font color="#0000FF" >Dép</font></a></td>
                        </tr>
                        <tr>
                            <td width="51"><img src="images/batavai_Icon.png"/></td>
                            <td width="137"><a><font color="#0000FF" >Giầy thể thao</font></a></td>
                        </tr>
                        <tr>
                            <td width="51"><img src="images/men_daytay.gif"/></td>
                            <td width="137"><a><font color="#0000FF">Giầy tây</font></a></td>
                        </tr>
                        <tr>
                            <td width="51"><img src="images/nu_thoitrang.gif"/></td>
                            <td width="137"><font color="#0000FF"><a>Giầy cao gót</a></font></td>
                        </tr>
                        <tr>
                            <td width="51"><img src="images/men_sandal.gif"/></td>
                            <td width="137"><a><font color="#0000FF">Sandals</font></a></td>
                        </tr>
                        <tr>
                            <td width="51"><img src="images/kids_hai.gif"/></td>
                            <td width="137"><font color="#0000FF">Hài</font></td>
                        </tr>
                    </table></td>
                <td colspan="4" valign="top"><!-- InstanceBeginEditable name="MainContent" --><table width="100%" border="1" bordercolor="#FFFFFF" cellspacing="0" cellpadding="5">
                        <tr >
                            <td colspan="2" background="images/Bartop.gif"><strong><font color="#FFFFFF">Kết quả tìm kiếm</font></strong></td>
                        </tr>
                        <tr>
                             <%int soTrang = SanPhamDAO.tinhSoTrang(maThuongHieu, maLoai, size, giaBan, soLuongSanPhamTrenTrang);
                                %>
                            <td colspan="2">Trang
                               
                                <!--BatDauMotTrang-->
                                <%
                                    for (int i = 1; i <= soTrang; i++) {
                                %>
                               <a href="TimKiem.jsp?maThuongHieu=<%=ThuongHieu%>&Trang=<%=i%>"><%=i%></a> | 
                               <%}%> 
                            </td>
                                
                            <!--KetThucMotTrang-->
                        </tr>
                        <!--BatDau-->
                        <tr>
                            <td>   
                                <%                                    
                                List<SanPham> dsSanPham = SanPhamDAO.timSanPham(maThuongHieu, maLoai, size, giaBan, trang, soLuongSanPhamTrenTrang);
                                    for (int i = 0;
                                            i < dsSanPham.size();
                                            i++) {
                                        SanPham s = dsSanPham.get(i);

                                %>
                                <table width="100%" border="0" cellspacing="0" cellpadding="5">
                                    <tr>
                                        <td width="30%" rowspan="6" valign="top"><a href="ChiTietSanPham.jsp?MaSanPham=<%=s.getMaSanPham()%>"><img src="images/GiayTheThao.png" alt="#" width="250" height="171" border="0" /></a></td>
                                        <td><a href="ChiTietSanPham.jsp?MaSanPham=<%=s.getMaSanPham()%>"><%=s.getMaSanPham()%></a></td>
                                    </tr>
                                    <tr>
                                        <td>Xuất xứ: <strong><%=s.getXuatXu()%></strong></td>
                                    </tr>
                                    <tr>
                                        <td>Giá bán: <strong><font color="#FF0000"><%=s.getGiaBan()%></font></strong>VNĐ</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Số lượng online:<strong><font color="#FF0000"> <%=s.getSoLuong()%> </font></strong> đôi</td>
                                    </tr>
                                    <tr>
                                        <td valign="top"><a href="ChiTietSanPham.jsp?MaSanPham=<%=s.getMaSanPham()%>"><img src="images/Button-chitiet.jpg" width="80" border="0" /></a></td>
                                    </tr>
                                    <tr>
                                        <td valign="top"><a href="GioHang.jsp?action=DatMua&maSanPham=<%=s.getMaSanPham()%>"><img src="images/Button-datmua.jpg" border="0" width="80"/></a></td>
                                    </tr>
                                </table>
                                <%}%> 
                            </td>           
                        </tr>

                        <!--KetThucCuonSach-->

                    </table><!-- InstanceEndEditable --></td>
            </tr>
            <tr align="center">
                <td colspan="5" background="images/Bartop.gif">&nbsp;</td>
            </tr>
            <tr align="center">
                <td colspan="5">                   
                    <%
                        if (session.getAttribute("username")==null) {
                    %>    
                    <p align="right"><a style="text-decoration:none" href="DangNhap.jsp"><font color="#0000FF"><strong>Đăng nhập &nbsp;&nbsp;  </strong></font></a> 
                        <a style="text-decoration:none" href="DangKy.jsp"><font color="#0000FF"><strong>Đăng ký&nbsp;</strong></font></a></p>                    
                        <%} else {
                        %>
                    <p align="right"><a >Chào: <font color="#0000FF"><strong><%=session.getAttribute("username")%> ||</strong></font></a> 

                        <a style="text-decoration:none" href="TrangChu.jsp?logout=true"><font color="#0000FF"><strong>Thoát</strong></font></a></p>
                        <%}
                        %>      
                </td>
            </tr>
            <tr align="center">
                <td colspan="5"><strong>@ 2012 Le Khanh Nhac </strong> <a href="#" target="_blank">Terms &amp; Privacy</a></td>
            </tr>
        </table>
    </body>
    <!-- InstanceEnd --></html>

